package com.example.author.controller;

import com.example.book.entity.Book;
import com.example.book.service.IBookService;
import com.example.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/author")
@Slf4j
public class AuthorBookController {
    @Autowired
    private IBookService bookService;
    /**
     * 添加图书
     * @param book
     * @return
     */
    @ApiOperation(value = "添加图书")
    @PostMapping
    public ResponseResult add(@RequestBody Book book){
        return bookService.addBook(book);
    }

    /**
     * 查询作者的作品
     * @param authorId 作者id
     * @return
     */
    @ApiOperation(value = "查询作者的作品")
    @GetMapping("/book")
    public ResponseResult authorBook(Long authorId){
        return ResponseResult.okResult(bookService.authorBook(authorId));
    }

    /**
     * 查询作者的最新作品
     * @param authorId 作者id
     * @return
     */
    @ApiOperation(value = "查询作者的最新作品")
    @GetMapping("/bookByTime")
    public ResponseResult authorBookByTime(Long authorId){
        return ResponseResult.okResult(bookService.authorBookByTime(authorId));
    }


}
